<?php
class LoginAction extends Action{
    
    public function login(){
        //global $cookieTools;
        //$qiaoba = $cookieTools->getCookie('qiaoba');
        //$this->smarty->assign("qiaoba",$qiaoba);
        $this->assign("smarty",'/manage/page/login/login.html');
        
        return $this->SMARTY;
    }
    
    public function testSmarty(){
        //$this->smarty->caching = false;                       //是否缓存
        $this->smarty->cache_lifetime = 300;                 //缓存时间，300秒5分钟
        
        $this->smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill",true);
        $this->smarty->assign("FirstName",array("John","Mary","James","Henry"));
        $this->smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
        $this->smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
                array("I", "J", "K", "L"), array("M", "N", "O", "P")));
        
        $this->smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
                array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
        
        $this->smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
        $this->smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
        $this->smarty->assign("option_selected", "NE");
        
        $this->assign("smarty",'/manage/page/login/testSmarty.html');
        
        return $this->SMARTY;
    }
    
    public function sendMail(){
        tsLoad('/include/phpmailer/class.phpmailer.php');
        $mail = new PHPMailer(true); //实例化PHPMailer类,true表示出现错误时抛出异常
        $mail->IsSMTP(); // 使用SMTP
        try {
            $mail->CharSet ="UTF-8";//设定邮件编码
            $mail->Host       = "smtp.126.com"; // SMTP server
            $mail->SMTPDebug  = 1;// 启用SMTP调试 1 = errors  2 =  messages
            $mail->SMTPAuth   = true;// 服务器需要验证
            $mail->Port       = 25;//默认端口
            $mail->Username   = "dongheng76"; //SMTP服务器的用户帐号
            $mail->Password   = "dh07019459";//SMTP服务器的用户密码
            $mail->AddReplyTo('dongheng76@126.com', '回复'); //收件人回复时回复到此邮箱
            $mail->AddAddress('747335569@qq.com', 'xianglv'); //收件人如果多人发送循环执行AddAddress()方法即可 还有一个方法时清除收件人邮箱ClearAddresses()
            $mail->SetFrom('dongheng76@126.com', '董恒');//发件人的邮箱
            $mail->Subject = '什麼標題都可能';
            $mail->Body = '單點登錄也測試成功了<font>12312312313diablo009</font>';
            $mail->IsHTML(true);
            $mail->Send();
            echo "Message Sent OK";
        } catch (phpmailerException $e) {
            echo $e->errorMessage();//从PHPMailer捕获异常
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
    
    public function loginService(){
        session_start();
        // 把 NuSOAP 的源文件包含到当前的代码文件里
        tsLoad('/include/nusoap/nusoap.php');
        // 初始化客户端对象，这个对象是类 soapclient 的一个实例，
        // 把服务程序的 URL 地址传递给soapclient类的构造函数。
        $client = new soapclient('http://login.yufeikj.com/service/login/LoginHandleService.php');
        
        // 参数
        $parameters = array(
                '董恒',
                'dh07019459'
        );
        // 利用客户端对象的 call 方法调用 WEB 服务的程序
        // 客户端对象的 getError() 方法可以用来检查调用过程是否出现错误。
        // 如果没有错误， getError() 方法返回 false ；如果有错误， getError()方法返回错误信息。
        if (! $err = $client->getError()) {
            $result = $client->call('loginHandleService', $parameters);
            var_dump($result);
        } else {
            echo " error :", htmlentities($err, ENT_QUOTES);
        }
    }
    
    public function loginService1(){
        session_start();
        try {
            //实例化客户端
            /*If working in WSDL mode, this parameter is optional. If working in non-WSDL mode, the location and uri options must be set, where location is the URL to request and uri is the target namespace of the SOAP service.
             */
            $client = new SoapClient(null, // non-WSDL模式，不指定WSDL文件
                    array('location'  =>"http://login.yufeikj.com/service/login/LoginHandleService1.php?wsdl",
                            'uri' => "http://login.yufeikj.com"));
        
            //调用服务端方法，并打印出返回结果
            $result = $client->loginHandleService('董恒','dh07019459');
            var_dump($result);
        } catch (SoapFault $fault){
            echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
        }
    }
    
    public function loginHandle(){
    	global $param;
    	$params = $param->getParams();
    	
        tsLoad('/manage/busi/SysUserBusi.class.php');
        $sysUserBusi = new SysUserBusi();
        $result = $sysUserBusi->loginSysUser($params);
        $this->assign('result',$result);

        return $this->JSON;
    }
    
    /**
     * 注销当前账户
     */
    public function quitLogin(){
    	global $param,$userSession;
    	$userSession->cancelLogin();
        $this->assign('result',1);
        
        return $this->JSON;
    }
    
    public function checkUserLogin(){
    	global $userSession;
    	$userInfo = $userSession->getUserSession();
    	if(!isset($userInfo["userId"]))
    		$this->assign('result',0);
    	else
    		$this->assign('result',1);
    	return $this->JSON;
    }
}
?>